<template>
  <vs-popup classContent="popup-example" v-bind="$attrs" v-on="$listeners">
    <slot></slot>
    <div class="popFoot mt-12 mb-5">
      <div v-if="btnGroup&&btnGroup.length>=0">
        <vs-button v-for="(item,index) in btnGroup" :key="index" size="small" color="primary" :type="item.type"
          :class="item.class" @click="handleFun(item.funName)">
          {{item.name}}
        </vs-button>
      </div>
      <div v-else>
        <vs-button @click="handleCancel" color="primary" type="border" size="small" class="mr-8">取消</vs-button>
        <vs-button @click="handleComfirm" :disabled="!isValid" color="primary" size="small">确定</vs-button>
      </div>
    </div>
  </vs-popup>
</template>

<script>
  export default {
    name: "vx-popup",
    // props: ["width"],
    data() {
      return {
        canScroll: true
      };
    },
    props: {
      width: {
        type: String
      },
      height: {
        type: String
      },
      isValid: {
        type: Boolean,
        default: true
      },
      btnGroup: {
        type: Array,
        required: false,
        default: () => null
      }
    },
    mounted() {
      this.$el.querySelector(".vs-popup").style.width = this.width;
    },
    watch: {
      $attrs: {
        handler: function (val) {
          if (val.active) {
            // document.body.style.overflowY = "hidden";
            this.canScroll = false;

          } else {
            // document.body.style.overflowY = "auto";
            this.canScroll = true;
          }
        },
        deep: true
      },
      canScroll: function (newVal) {
        if (newVal) {
          document.body.style.overflowY = "auto";
        } else {
          document.body.style.overflowY = "hidden";
        }
      },
      hasValidate(nv) {
        console.log(nv);
      }
    },
    methods: {
      //弹窗确认
      handleComfirm() {
        this.$emit("confirmPopup");
      },
      //弹窗取消
      handleCancel() {
        this.$emit("cancelPopup");
      },
      handleFun(funName) {
        this.$emit(funName);
      }
    }
  };

</script>

<style lang="scss">
  @import '@/assets/scss/baseColor.scss';

  .vs-popup--title h3,
  .vs-notifications h3 {
    color: $mainColor;
  }

  .popFoot {
    display: flex;
    justify-content: center;
  }

  .vs-popup--header {
    // background: transparent;
    // margin-bottom: 20px;
    height: 45px;
    padding-left: 10px;
  }

  // .vs-popup--title {
  //   left: 28px;
  // }

  // .vs-popup--title h3 {
  //   padding: 0;
  //   font-size: 2rem;
  //   text-align: center;
  //   margin-top: 35px;
  // }

  .vs-popup--close {
    top: -10px;
  }

  // .vs-button {
  //   padding: 5px 30px !important;
  //   border-radius: 0;
  //   font-size: 16px !important;
  // }

  .con-vs-popup .vs-popup--content {
    padding: 1rem 2rem !important;
  }




</style>
